#!/usr/bin/python
# -*- coding: UTF-8 -*-

import os
import shutil

def delete_proj_files():
    """
    NOTE: 必须从源码顶层目录运行这个脚本;
    没有注释的行会被删除,
    被注释的行会被保留。
    """
    current_path = os.getcwd()

    remove_list = [
        "platforms/ln882x/components/wifi/wifi_cfg/",     # NOTE: 必须删除
        "platforms/ln882x/components/wifi/wifi_if/",      # NOTE: 必须删除
        "platforms/ln882x/components/wifi/wifi_mac/",     # NOTE: 必须删除
        "platforms/ln882x/components/wifi/CMakeLists.txt",     # NOTE: 必须删除

        # "platforms/ln882x/components/wifi/wifi_manager/", # 保留
        # "platforms/ln882x/components/wifi/wifi_port/",    # 保留
        # "platforms/ln882x/components/wifi/wifi.h",       # 保留

        "platforms/ln882x/mcu/driver_ln882x/CMakeLists.txt", # 删除
        "platforms/ln882x/mcu/driver_ln882x/src/ll/",    # 删除
        "platforms/ln882x/mcu/driver_ln882x/inc/reg",    # 删除

        "platforms/ln882x/tools/ota_tools/",             # 删除

        "build/",  # 删除
    ]

    # 遍历，删除
    for path in remove_list:
        temp_path = os.path.join(current_path, path)
        print(temp_path)
        if not os.path.exists(temp_path):
            continue
        if os.path.isdir(temp_path):
            if os.listdir(temp_path):
                print("    |")
                print("    ------>")
                print("full dir deleted...")
                shutil.rmtree(temp_path)
            else:
                print("    |")
                print("    ------>")
                print("empty dir deleted...")
                os.removedirs(temp_path)
        elif os.path.isfile(temp_path):
            print("    |")
            print("    ------>")
            print("file deleted...")
            os.remove(temp_path)
        else:
            pass


def delete_this_script():
    abspath = __file__
    os.remove(abspath)


if __name__ == "__main__":
    print("\r\n")
    print("----------------------------------------")

    delete_proj_files()
    delete_this_script()


    print("----------------------------------------")
    print("\r\n")
